package com.gege.homework1;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author gechenpeng
 * @date 2021-04-16
 */
@Slf4j
@AllArgsConstructor
public class LogHandler implements InvocationHandler {

    private Object target;

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        log.info("开始");
        long start = System.currentTimeMillis();

        Object result = method.invoke(target, args);

        log.info("结束, 花了 {} 毫秒", System.currentTimeMillis() - start);

        return result;
    }
}
